package com.example.demo.demo1;

import io.netty.channel.*;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpRequestEncoder;
import io.netty.handler.codec.http.HttpResponseDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: weijun.zou
 * Date: 2018-06-01
 * Time: 17:45
 */
public class Client extends PrintHandler {


    HttpResponseDecoder httpResponseDecoder;
    HttpRequestEncoder httpRequestEncoder;
    HttpResponseEncoder httpResponseEncoder;
    HttpRequestDecoder httpRequestDecoder;
    SimpleChannelInboundHandler simpleChannelInboundHandler;

    ObjectEncoder objectEncoder;
    ObjectDecoder objectDecoder;

    ChannelPipeline channelPipeline;

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        super.channelActive(ctx);
        final ChannelFuture f = ctx.writeAndFlush("client active");
        f.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                assert f == future;
                ctx.close();
            }
        });
    }

    public static void main(String[] args) throws InterruptedException {
        ClientUtils.startClient("localhost", 9999, new Client());
    }
}
